package com.zyark.web.filter;

import com.zyark.domain.SysUser;
import com.zyark.service.SysUserService;
import com.zyark.web.Constants;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * ron
 * 获取用户信息
 */
public class SysUserFilter extends PathMatchingFilter {

    @Resource
    private SysUserService sysUserService;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        String username = (String)SecurityUtils.getSubject().getPrincipal();
        SysUser sysUser = new SysUser(username);
        SysUser mySysUser = sysUserService.selectOne(sysUser);
        request.setAttribute(Constants.CURRENT_USER,mySysUser);
        return true;
    }
}
